import random
import re
import secrets

def _randint(a, b):
    return secrets.choice( list( range(a, b+1) ) )

class PassGen:
    def __init__(self, chars="A-Za-z0-9_@", lens=None):
        if not chars:
            chars = "A-Za-z0-9_@"

        if not lens:
            lens = 20

        self.lens = int(lens)
        self.chars = re.findall(r'(.-.)|(.)', chars)

    def gen(self):
        chars = ""

        for i in range(int(self.lens)):
            #select_r_gr = self.chars[ random.randint( 0, len(self.chars)-1 ) ]
            select_r_gr = self.chars[ _randint(0, len(self.chars)-1 ) ]

            if select_r_gr[0]: # if .-.
                select_chars = select_r_gr[0].split("-")
                chars += chr( _randint( ord(select_chars[0]), ord(select_chars[1]) ) )
            else: # if .
                chars += str( select_r_gr[1] )

        return chars

if __name__ == "__main__":
    pg = PassGen()
    print(pg.gen())
    print(_randint(4, 10))
